//
//  MDCodeButton.m
//  jewelryMD
//
//  Created by 洪闽程 on 2018/7/25.
//  Copyright © 2018年 洪闽程. All rights reserved.
//

#import "MDCodeButton.h"

@implementation MDCodeButton
{
    //倒计时
    int  timeCount;
    
    NSTimer *timer;
}
-(void)awakeFromNib
{
    [super awakeFromNib];
  
    
}

-(void)sendCode
{
    
      timeCount=60;
    
     timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(uploadtime:) userInfo:nil repeats:YES];
    
}

#pragma mark -- 短信
-(void)destroyTimer{
    if ([timer isValid]){
        [timer invalidate];
        
        timer = nil;
    }
}
#pragma mark 刷新定时器
-(void)uploadtime:(id)sender
{
    if (timeCount==0)
    {
        [self destroyTimer];
        self.userInteractionEnabled = YES;
        [self setTitle:@"获取验证码" forState:UIControlStateNormal];
    }else{
        [self setTitle:[NSString stringWithFormat:@"%d秒",timeCount] forState:UIControlStateNormal];
        self.userInteractionEnabled=NO;
        timeCount--;
    }
}

@end
